home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
COPYMOVE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
16KB
|
575 lines
#include "pt.h"
#include "string.h"
void pascal
/* XTAG:updateFile */
updateFile(fileId, cp, len, tryShortcut)
int fileId, tryShortcut;
long cp, len;
{
extern unsigned char msgBuffer[];
extern struct window *windowList;
extern struct window *selWindow;
extern long selBegin, selEnd;
extern unsigned char *screenMap;
extern int debug;
extern int scrRows, scrCols;
register struct window *w;
struct window *lastW;
int i, n, minRow, maxRow, row2, col1, col2;
long cp1;
lastW = NULL;
w = windowList;
while( w != NULL ) {
if( w->fileId == fileId )
lastW = w;
w = w->nextWindow;
}
/* If the top window is the only window showing this file */
/* and no line feed was deleted and the line is in the window */
/* then try to do it faster */
if( tryShortcut && lastW == windowList
&& cp < windowList->posBotline ) {
posToxy(windowList, selBegin, &row2, &col2);
col1 = windowList->col1 + 1;
col2 = windowList->col2 - 1;
setMap(row2, col1, row2, col2, 1, 0x07);
n = -1;
cp1 = prevLine(windowList->fileId, selBegin, &n);
fillLine(windowList, cp1, row2, col1, col2);
updateScreen(row2, row2);
return;
}
/* redraw the affected windows */
setMap(0, 0, scrRows-1, scrCols-1, 1, 0x07);
w = windowList;
minRow = scrRows;
maxRow = -1;
while( 1 ) {
if( w->fileId != fileId ) {
/* just mask off the window area so later */
/* windows (underneath it) will not repaint it */
col1 = w->col1;
row2 = w->row2;
n = w->col2 - col1 + 1;
for(i = w->row1; i <= row2; i++)
memset(screenMap+scrCols*i+col1, 0, n);
} else {
/* repaint the window as necessary */
if( cp <= w->posBotline )
w->posBotline += len;
if( cp < w->posTopline ) {
cp1 = w->posTopline + len;
/* remember: len < 0 for a delete */
/* a delete overlapping this window? */
if( cp1 < cp ) {
n = -1;
cp1 = prevLine(w->fileId, cp, &n);
}
/* recalculate the line number by letting */
/* prevLine count as far back as it can */
n = 30000;
prevLine(w->fileId, cp1, &n);
w->numTopline = n + 1;
w->posTopline = cp1;
}
drawWindow(w);
if( w->row1 < minRow )
minRow = w->row1;
if( w->row2 > maxRow )
maxRow = w->row2;
}
if( w == lastW )
break;
w = w->nextWindow;
}
if( maxRow != -1 )
updateScreen(minRow, maxRow);
}
void pascal
/* XTAG:updateTops */
updateTops(fileId, cp, len)
int fileId;
long cp, len;
{
extern unsigned char msgBuffer[];
extern struct window *windowList;
extern int debug;
register struct window *w;
struct window *lastW;
int n;
long cp1;
lastW = NULL;
w = windowList;
while( w != NULL ) {
if( w->fileId == fileId )
lastW = w;
w = w->nextWindow;
}
/* adjust the data of the affected windows */
w = windowList;
while( 1 ) {
if( w->fileId == fileId ) {
if( cp >= w->posBotline )
goto nextWindow;
else
w->posBotline += len;
if( cp < w->posTopline ) {
cp1 = w->posTopline + len;
/* a delete overlapping this window? */
if( cp1 < cp ) {
n = -1;
cp1 = prevLine(w->fileId, cp, &n);
}
/* recalculate the line number by letting */
/* prevLine count as far back as it can */
n = 30000;
prevLine(w->fileId, cp1, &n);
w->numTopline = n + 1;
w->posTopline = cp1;
}
}
nextWindow:
if( w == lastW )
break;
w = w->nextWindow;
}
}
void pascal
/* XTAG:exchWithScrap */
exchWithScrap()
{
extern unsigned char msgBuffer[];
extern struct changeItem scrapBuffer;
extern struct changeItem *change;
extern int nextChange;
extern long selBegin, selEnd;
extern struct window *selWindow;
extern struct openFile *files;
extern unsigned char *userMessages[];
long length;
register struct changeItem *thisChange;
struct piece *firstPiece;
/* check if this is a readOnly file */
if( files[selWindow->fileId].readOnly ) {
sprintf(msgBuffer, userMessages[READONLYFILE],
files[selWindow->fileId].origName);
msg(msgBuffer, 1);
return;
}
/* remember what was in the scrap */
firstPiece = scrapBuffer.firstPiece;
length = scrapBuffer.length;
/* prevent this from getting freed when the scrap buffer is reused */
scrapBuffer.firstPiece = NULL;
/* move the selection into the scrap */
deleteChars(selWindow->fileId, NOUPDATE, 1);
/* record in the change history */
IncrementNextChange();
thisChange = &change[nextChange];
thisChange->type = CINSERT;
thisChange->position = selBegin;
thisChange->length = length;
thisChange->fileId = selWindow->fileId;
thisChange->firstPiece = firstPiece;
/* copy the old scrap into the file */
copyPieces(firstPiece, selWindow, selBegin, length, 1);
/* free the scrap pieces */
freePieces(firstPiece);
}
void pascal
/* XTAG:copyToScrap */
copyToScrap(fromWindow, fromBegin, fromEnd)
struct window *fromWindow;
long fromBegin, fromEnd;
{
extern unsigned char msgBuffer[];
extern struct changeItem scrapBuffer;
extern long addPosition;
extern int selMode;
extern int scrapMode;
int fromId;
long fb, copyLength;
register struct piece *tempPP;
fromId = fromWindow->fileId;
/* eliminate the EOF marker from the selection */
fb = fileSize(fromId);
if( fromEnd >= fb ) {
if( fromBegin < fb )
fromEnd = fb-1;
else /* only the EOF symbol is selected */
return;
}
copyLength = fromEnd - fromBegin + 1;
/* free the old scrap buffer pieces */
freePieces(scrapBuffer.firstPiece);
/* record in the scrap buffer */
scrapBuffer.type = 1;
scrapBuffer.length = copyLength;
tempPP = getFreePiece();
scrapBuffer.firstPiece = tempPP;
scrapMode = selMode;
tempPP->file = ADDFILE;
tempPP->position = addPosition;
fb = fromBegin;
while( fb <= fromEnd ) {
writeChar( readChar(fromId, fb++), addPosition++);
}
tempPP->length = copyLength;
}
void pascal
/* XTAG:insScrap */
insScrap(doInsert)
int doInsert;
{
extern unsigned char msgBuffer[];
extern struct window *selWindow;
extern long selBegin, selEnd;
extern struct changeItem scrapBuffer;
extern long addPosition;
extern struct openFile *files;
extern struct changeItem *change;
extern int nextChange;
extern int selMode;
extern int scrapMode;
extern int maxFiles;
extern unsigned char *userMessages[];
long limit, logByte;
struct piece *tempPP, *oldScrap;
register struct openFile *ff;
register struct changeItem *thisChange;
/* check if this is a readOnly file */
if( files[selWindow->fileId].readOnly ) {
sprintf(msgBuffer, userMessages[READONLYFILE],
files[selWindow->fileId].origName);
msg(msgBuffer, 1);
return;
}
/* See if the text in the scrap buffer is in an edit file rather */
/* then in the add file. If it is we need to copy it to the add */
/* file. */
if( !scrapBuffer.type ) {
/* keep a pointer to the old piece list */
oldScrap = scrapBuffer.firstPiece;
/* scrapBuffer.length will not change */
/* get a new piece and initialize the fields */
tempPP = getFreePiece();
tempPP->file = ADDFILE;
tempPP->position = addPosition;
tempPP->length = scrapBuffer.length;
/* this will be the new scrapBuffer piece list */
scrapBuffer.type = 1; /* now it is addFile only type */
scrapBuffer.firstPiece = tempPP;
/* Now copy the characters into the add file */
logByte = 0;
limit = scrapBuffer.length;
/* simulate a file this was deleted from */
ff = &files[maxFiles];
ff->hiLogBuffer = -1;
ff->origHandle = scrapBuffer.fileId;
ff->fileSize = limit;
ff->logPiece = oldScrap;
ff->loLogPiece = 0;
ff->hiLogPiece = oldScrap->length - 1;
while( logByte < limit ) {
/* copy the characters in pp to the add file */
writeChar( readChar(maxFiles, logByte++),
addPosition++);
}
freePieces(oldScrap); /* free the old piece chain */
}
if( doInsert ) {
/* record in the change history */
IncrementNextChange();
thisChange = &change[nextChange];
thisChange->type = CCOPY;
selMode = scrapMode;
selBegi